Gestures allow Users to interact with Views by using different motions of the fingers.
Gestures can be implemented with following Modifiers: .gesture, .onLongPressGesture & .onTapGesture.
@GestureState is used to update variable from within .updating() method.
Inside the Gesture use self to refer to affected View.
We use @State Variable which influences .scaleEffect() and which is changed when we Tap on the View.
Tap to change size with animation
struct ContentView: View {
@State private var isPressed = false
var body: some View {
Circle()
.fill(Color.green)
.frame(width: 50, height: 50)
.scaleEffect(isPressed ? 5 : 1)
.animation(.easeInOut)
.onTapGesture{
self.isPressed.toggle()
}
}
}
Initial size Size after tapping (with animation)